﻿using Roton.Memory;
using Roton.ZZT;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Roton.Wrapper
{
    /// <summary>
    /// Adapts IVector to a Segment object.
    /// </summary>
    class VectorWrapper : IVector
    {
        protected int offset;
        protected Segment segment;

        public VectorWrapper(int offset, Segment segment)
        {
            this.offset = offset;
            this.segment = segment;
        }

        public override string ToString()
        {
            return "[" + X.ToString() + "," + Y.ToString() + "]";
        }

        public IVector Add(IVector other)
        {
            return new VectorValue(X + other.X, Y + other.Y);
        }

        public IVector Subtract(IVector other)
        {
            return new VectorValue(X - other.X, Y - other.Y);
        }

        public int X
        {
            get
            {
                return segment.Read16(offset);
            }
            set
            {
                segment.Write16(offset, value);
            }
        }

        public int Y
        {
            get
            {
                return segment.Read16(offset + 2);
            }
            set
            {
                segment.Write16(offset + 2, value);
            }
        }
    }
}
